Skip to content

adaptertest: fix goroutine/test lifecycle race in testReleasing#195

Open
andrewwormald wants to merge 1 commit intomainfrom
fix/memrolescheduler-race-condition
Open

adaptertest: fix goroutine/test lifecycle race in testReleasing#195
andrewwormald wants to merge 1 commit intomainfrom
fix/memrolescheduler-race-condition

Conversation

@andrewwormald
Copy link
Copy Markdown
Collaborator

@andrewwormald andrewwormald commented Apr 30, 2026

Summary

testReleasing spawned two nested goroutines that called require.NoError and require.ErrorIs directly. When the 5-second timeout path fired, the test completed before those goroutines finished, causing a panic:

panic: Fail in goroutine after TestRoleScheduler/Ensure_role_is_released_on_context_cancellation has completed
    adapters/adaptertest/rolescheduler.go:87

Fix: replace the in-goroutine require.* calls with buffered error channels (outerErr, innerErr) and assert in the test goroutine, which is the correct pattern per the Go testing docs.

Test plan

  • go test ./adapters/memrolescheduler/... -count=10 -race passes (verified locally at count=5)

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

No end-user visible changes. This release includes internal test infrastructure improvements to enhance test reliability and error handling.

  • Tests
    • Improved test coordination and error reporting mechanisms.

require.NoError and require.ErrorIs were called inside goroutines that
could outlive the test when the 5-second timeout path fired. Move all
assertions into the test goroutine by communicating results back via
buffered error channels.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a788c7c0-c64e-4d05-bbfa-e623747446ec

📥 Commits

Reviewing files that changed from the base of the PR and between 8a09a96 and ded7bcb.

📒 Files selected for processing (1)
  • adapters/adaptertest/rolescheduler.go

📝 Walkthrough

Walkthrough

The test in adapters/adaptertest/rolescheduler.go refactors its synchronisation mechanism between two concurrent RoleScheduler.Await callers. The coordination logic shifts from a simple boolean "passed" signal to two separate buffered error channels—one for each goroutine's result. The outer goroutine now directly sends its await error into the outer channel and halts setup upon failure, whilst the inner goroutine sends its error without inline assertion. The main select statement replaces the previous boolean-based success condition with explicit error channel waits, each with appropriate error validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hops through channels fair,
From booleans to errors with care,
Two await calls now coordinate true,
With buffered streams replacing the few,
Testing grows wiser, step by step anew. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main change: fixing a goroutine/test lifecycle race condition in the testReleasing test.
Description check ✅ Passed The description thoroughly explains the problem (panic from assertions in goroutines after test completion), the solution (buffered error channels and moving assertions to main test goroutine), and includes a test plan.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/memrolescheduler-race-condition

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant